/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.Etbl_Car_models;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Mr.aUgust
 */
public class DALtbl_Car_models extends BaseConnection{
    CallableStatement clbStm=null;
    ResultSet rs=null;
      public boolean addtbl_Car_models(Etbl_Car_models obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Car_models_add(?)}");
            clbStm.setString("name", obj.getName());                                                     
            clbStm.execute();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_models.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      
      public boolean edittbl_Car_models(Etbl_Car_models obj){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Car_models_update(?,?)}");
            clbStm.setInt("carmodel_Id",obj.getCarmodel_Id());
            clbStm.setString("name", obj.getName());                                    
            clbStm.execute();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_models.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      
      public boolean deletetbl_Car_models(int carmodel_Id){
        try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Car_models_delete(?)}");
            clbStm.setInt("carmodel_Id",carmodel_Id);              
            clbStm.execute();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_models.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
      }
      public Etbl_Car_models getOne_CarModel(int Carmodel_id){
        Etbl_Car_models OCarModel=new Etbl_Car_models();
          try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Car_models_get(?)}");
            clbStm.setInt("carmodel_Id", Carmodel_id);
            rs=clbStm.executeQuery();
            if(rs.next()){
                OCarModel.setCarmodel_Id(Carmodel_id);
                OCarModel.setName(rs.getString("name"));
            }
            clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_models.class.getName()).log(Level.SEVERE, null, ex);
        }
          finally{
              return OCarModel;
          }
      }
      public ArrayList<Etbl_Car_models> getListCarsModel(String orderBy, String ASCorDESC, String WhereClause, int PagingIndex, int PagingSize){
       ArrayList<Etbl_Car_models> arrCarsModel = new ArrayList<Etbl_Car_models>();
          try {
            getConnection();
            clbStm=cnn.prepareCall("{call tbl_Car_models_paged(?,?,?,?,?)}");
             clbStm.setString("OrderBy", orderBy);
              clbStm.setString("TangGiam", ASCorDESC);
              clbStm.setString("WhereClause", WhereClause);
              clbStm.setInt("PageIndex", PagingIndex);
              clbStm.setInt("PageSize", PagingSize);
              rs=clbStm.executeQuery();
              DALTotalPageIndex.getTotalPage("tbl_Car_models", WhereClause, PagingSize);
              while(rs.next()){
                  Etbl_Car_models OCarModel=new Etbl_Car_models();
                OCarModel.setCarmodel_Id(rs.getInt("carmodel_Id"));
                OCarModel.setName(rs.getString("name"));
                arrCarsModel.add(OCarModel);
            }
            clbStm.close();
            rs.close();
            releaseConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DALtbl_Car_models.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
              return arrCarsModel;
          }
      }
}
